$(document).ready(function () {
    //alert("ppp")
    //var list = ["C01","C02","C01","C02","C01","C02","C01","C02"];
    var deviceNumber = getParams("deviceNumber");
    // deviceNumber = "1";
    // var obj = {"deviceNumber":deviceNumber};
    var list = {};
    $.ajax({
        type: "post",
        url: "overdueOpening",
        async: true,
        contentType: "application/json; charset=utf-8",
        data: deviceNumber,
        dataType: "json",
        success: function (data) {
            console.log(data)

            // var jsonStr = eval('(' + data + ')');
            console.log(data.result)
            if (data.result == true) {
                list = eval('(' + data.respJson + ')');
                console.log(list[0]);
                console.log(list[0].latticeNumber);
                show(list);

            }
        }
    });

});

function getParams(key) {
    var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
};
console.log("deviceNumber:" + getParams("deviceNumber"));//输出aa

function show(list) {
    if (list.length != 0) {
        var z = 0;
        var n = parseInt((list.length + 5) / 6); //有几行
        console.info(n);
        for (var j = 0; j < n; j++) {
            $("#tbody").append("<tr id='" + j + "tr'></tr>");
            z = list.length - 6 * j;
            if (z > 0) {
                if (z > 6) {
                    var count = 0;
                    for (var i = j * 6; i < (j + 1) * 6; i++) {
                        console.info(i + ":" + list[i]);
                        $("#" + j + "tr").append("<td><div class='u1_div' id='" + i + "diva' onclick='a(this)'>"
                            + "<input value='" + JSON.stringify(list[i]) + "' hidden='hidden'>"
                            + "<span id='s_text'>" + list[i].latticeNumber + "</span>"
                            + "<div class='u2_div' id='" + i + "divb' style=''></div>"
                            + "</div></td>");
                        count++;
                        if (count > 5)
                            break;
                    }
                } else {
                    for (var i = j * 6; i < list.length; i++) {
                        console.info(i + ":" + list[i]);
                        $("#" + j + "tr").append("<td><div class='u1_div' id='" + i + "diva' onclick='a(this)'>"
                            + "<input value='" + JSON.stringify(list[i]) + "' hidden='hidden' >"
                            + "<span id='s_text'>" + list[i].latticeNumber + "</span>"
                            + "<div class='u2_div' id='" + i + "divb' style=''></div>"
                            + "</div></td>");
                    }
                }
            }
        }
    }
}

function a(val) {
    var id = $(val).attr("id");//拿到div的id
    var latticeInfo = $("#" + id + " input").val();
    alert(latticeInfo);
    // var str =  $("#0diva input").val();
    clientScript.overOpeaning(latticeInfo);
}

function exitIndex() {
    clientScript.staffHome();
}


function home() {
    clientScript.home();
}
